/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @signatureAlgorithm = 'v2';
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('umeng-finplus', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetMessageStatusRequest {
  taskId?: string(name='TaskId'),
}

model GetMessageStatusResponseBody = {
  code?: string(name='Code'),
  data?: {
    mobile?: string(name='mobile'),
    requestId?: string(name='requestId'),
    status?: string(name='status'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model GetMessageStatusResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetMessageStatusResponseBody(name='body'),
}

async function getMessageStatusWithOptions(request: GetMessageStatusRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetMessageStatusResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.taskId)) {
    query['TaskId'] = request.taskId;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetMessageStatus',
    version = '2021-11-25',
    protocol = 'HTTPS',
    pathname = `/sms/message/status`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getMessageStatus(request: GetMessageStatusRequest): GetMessageStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getMessageStatusWithOptions(request, headers, runtime);
}

model SendBatchMessageRequest {
  batchFlag?: string(name='BatchFlag'),
  extendInfo?: string(name='ExtendInfo'),
  idType?: string(name='IdType'),
  phoneNumberJson?: string(name='PhoneNumberJson'),
  signNameJson?: string(name='SignNameJson'),
  specificChannel?: string(name='SpecificChannel'),
  templateCode?: string(name='TemplateCode'),
  templateParamJson?: string(name='TemplateParamJson'),
}

model SendBatchMessageResponseBody = {
  code?: string(name='Code'),
  data?: [ 
    {
      mobile?: string(name='mobile'),
      taskId?: string(name='taskId'),
    }
  ](name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
}

model SendBatchMessageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SendBatchMessageResponseBody(name='body'),
}

async function sendBatchMessageWithOptions(request: SendBatchMessageRequest, headers: map[string]string, runtime: Util.RuntimeOptions): SendBatchMessageResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.batchFlag)) {
    body['BatchFlag'] = request.batchFlag;
  }
  if (!Util.isUnset(request.extendInfo)) {
    body['ExtendInfo'] = request.extendInfo;
  }
  if (!Util.isUnset(request.idType)) {
    body['IdType'] = request.idType;
  }
  if (!Util.isUnset(request.phoneNumberJson)) {
    body['PhoneNumberJson'] = request.phoneNumberJson;
  }
  if (!Util.isUnset(request.signNameJson)) {
    body['SignNameJson'] = request.signNameJson;
  }
  if (!Util.isUnset(request.specificChannel)) {
    body['SpecificChannel'] = request.specificChannel;
  }
  if (!Util.isUnset(request.templateCode)) {
    body['TemplateCode'] = request.templateCode;
  }
  if (!Util.isUnset(request.templateParamJson)) {
    body['TemplateParamJson'] = request.templateParamJson;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SendBatchMessage',
    version = '2021-11-25',
    protocol = 'HTTPS',
    pathname = `/sms/message/send`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function sendBatchMessage(request: SendBatchMessageRequest): SendBatchMessageResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return sendBatchMessageWithOptions(request, headers, runtime);
}

